Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: impl ajv + typebox Validator #201

Merged
merged 1 commit into from
Apr 2, 2024
Merged

feat: impl ajv + typebox Validator #201

merged 1 commit into from
Apr 2, 2024

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Apr 1, 2024

closes #200

Summary by CodeRabbit

  • New Features

    • Introduced @eggjs/ajv-decorator for enhanced type validation and transformation in TypeScript projects.
    • Added @eggjs/tegg-ajv-plugin for parameter validation and type definition in Egg.js applications, with complete TypeScript support.
    • Implemented custom error handling for validation failures in Ajv.
    • Provided installation, configuration, and usage guidelines for tegg-dal-plugin in both egg and standalone modes.
  • Bug Fixes

    • Removed unnecessary await in Runner.ts for lifecycle utilities, enhancing performance.
  • Documentation

    • Updated README files with detailed information on the newly introduced plugins and their usage in projects.
    • Provided comprehensive installation and configuration instructions for the tegg-dal-plugin.
  • Tests

    • Added new tests for AJV validation, ensuring robust error handling and successful data validation.
    • Updated test configurations and imports to reflect changes in the framework.

@fengmk2 fengmk2 added the enhancement New feature or request label Apr 1, 2024
Copy link

coderabbitai bot commented Apr 1, 2024

Warning

Rate Limit Exceeded

@fengmk2 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 27 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between a411f04 and 3698ac7.

Walkthrough

The update introduces @eggjs/ajv-decorator for advanced type validation and transformation, leveraging @sinclair/typebox and Ajv. It simplifies request parameter validation in the Egg and Tegg frameworks, emphasizing ease of use with TypeScript decorators and enums for string transformations. The changes span across core and plugin directories, enhancing error handling, schema validation, and integrating the AJV plugin for improved validation processes within applications.

Changes

Files Summary
core/ajv-decorator/... Introduced @eggjs/ajv-decorator package with TypeScript decorators for validation using ajv and @sinclair/typebox.
core/tegg/ajv.ts
plugin/ajv/...
Added AJV plugin functionality for Egg and Tegg frameworks.
plugin/ajv/test/... Added tests and fixtures for the AJV plugin, including a FooController for request validation.
standalone/standalone/... Updated standalone runner to use @eggjs/tegg-ajv-plugin, including tests for AJV validation.

Assessment against linked issues

Objective Addressed Explanation
基于 typebox 提供请求入参 Validator 让参数校验无比简单 (#200)

Poem

In the land of code and bytes, where logic gleams and shines so bright,
A rabbit hopped, with joy it spoke, of validators wrapped in cloak.
"With @eggjs/ajv-decorator, so spry, we'll validate, no need to sigh.
🎩✨ For types and schemas, we now have means, in Egg's vast fields of green.
Let's hop along, with ease and fun, for coding tasks are now well done."

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

socket-security bot commented Apr 1, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@eggjs/[email protected] None 0 11 kB killagu
npm/@sinclair/[email protected] None 0 1.34 MB sinclair
npm/[email protected] eval Transitive: unsafe +5 1.57 MB esp
npm/[email protected] environment, filesystem, shell +7 134 kB fengmk2

🚮 Removed packages: npm/@eggjs/[email protected]

View full report↗︎

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7637fc3 and 233c724.
Files selected for processing (63)
  • core/ajv-decorator/README.md (1 hunks)
  • core/ajv-decorator/index.ts (1 hunks)
  • core/ajv-decorator/package.json (1 hunks)
  • core/ajv-decorator/src/enum/Transform.ts (1 hunks)
  • core/ajv-decorator/src/type/Ajv.ts (1 hunks)
  • core/ajv-decorator/tsconfig.json (1 hunks)
  • core/ajv-decorator/tsconfig.pub.json (1 hunks)
  • core/tegg/ajv.ts (1 hunks)
  • core/tegg/package.json (1 hunks)
  • plugin/ajv/README.md (1 hunks)
  • plugin/ajv/app.ts (1 hunks)
  • plugin/ajv/lib/Ajv.ts (1 hunks)
  • plugin/ajv/package.json (1 hunks)
  • plugin/ajv/test/ajv.test.ts (1 hunks)
  • plugin/ajv/test/fixtures/apps/ajv-app/config/config.default.js (1 hunks)
  • plugin/ajv/test/fixtures/apps/ajv-app/config/module.json (1 hunks)
  • plugin/ajv/test/fixtures/apps/ajv-app/config/plugin.js (1 hunks)
  • plugin/ajv/test/fixtures/apps/ajv-app/modules/demo/FooController.ts (1 hunks)
  • plugin/ajv/test/fixtures/apps/ajv-app/modules/demo/package.json (1 hunks)
  • plugin/ajv/test/fixtures/apps/ajv-app/package.json (1 hunks)
  • plugin/ajv/tsconfig.json (1 hunks)
  • plugin/ajv/tsconfig.pub.json (1 hunks)
  • plugin/ajv/typings/index.d.ts (1 hunks)
  • plugin/aop/app.ts (1 hunks)
  • plugin/aop/test/aop.test.ts (1 hunks)
  • plugin/config/test/DuplicateOptionalModule.test.ts (1 hunks)
  • plugin/config/test/ReadModule.test.ts (1 hunks)
  • plugin/controller/test/http/acl.test.ts (1 hunks)
  • plugin/controller/test/http/edgecase.test.ts (1 hunks)
  • plugin/controller/test/http/host.test.ts (1 hunks)
  • plugin/controller/test/http/middleware.test.ts (1 hunks)
  • plugin/controller/test/http/module.test.ts (1 hunks)
  • plugin/controller/test/http/params.test.ts (1 hunks)
  • plugin/controller/test/http/priority.test.ts (1 hunks)
  • plugin/controller/test/http/request.test.ts (1 hunks)
  • plugin/controller/test/lib/ControllerMetaManager.test.ts (1 hunks)
  • plugin/controller/test/lib/EggControllerLoader.test.ts (1 hunks)
  • plugin/controller/test/lib/HTTPMethodRegister.test.ts (1 hunks)
  • plugin/dal/app.ts (1 hunks)
  • plugin/dal/package.json (1 hunks)
  • plugin/dal/test/dal.test.ts (1 hunks)
  • plugin/dal/test/fixtures/apps/dal-app/config/config.default.js (1 hunks)
  • plugin/eventbus/test/eventbus.test.ts (1 hunks)
  • plugin/orm/test/index.test.ts (1 hunks)
  • plugin/schedule/test/schedule.test.ts (1 hunks)
  • plugin/tegg/test/AccessLevelCheck.test.ts (1 hunks)
  • plugin/tegg/test/BackgroundTask.test.ts (1 hunks)
  • plugin/tegg/test/DynamicInject.test.ts (1 hunks)
  • plugin/tegg/test/EggCompatible.test.ts (1 hunks)
  • plugin/tegg/test/ModuleConfig.test.ts (1 hunks)
  • plugin/tegg/test/NoModuleJson.test.ts (1 hunks)
  • plugin/tegg/test/OptionalModule.test.ts (1 hunks)
  • plugin/tegg/test/OptionalPluginModule.test.ts (1 hunks)
  • plugin/tegg/test/SameProtoName.test.ts (1 hunks)
  • plugin/tegg/test/Subscription.test.ts (1 hunks)
  • plugin/tegg/test/close.test.ts (1 hunks)
  • standalone/standalone/package.json (1 hunks)
  • standalone/standalone/src/Runner.ts (3 hunks)
  • standalone/standalone/test/fixtures/ajv-module-pass/foo.ts (1 hunks)
  • standalone/standalone/test/fixtures/ajv-module-pass/package.json (1 hunks)
  • standalone/standalone/test/fixtures/ajv-module/foo.ts (1 hunks)
  • standalone/standalone/test/fixtures/ajv-module/package.json (1 hunks)
  • standalone/standalone/test/index.test.ts (2 hunks)
Files skipped from review due to trivial changes (12)
  • core/ajv-decorator/package.json
  • core/ajv-decorator/src/enum/Transform.ts
  • core/ajv-decorator/tsconfig.pub.json
  • core/tegg/ajv.ts
  • plugin/ajv/test/fixtures/apps/ajv-app/modules/demo/package.json
  • plugin/ajv/test/fixtures/apps/ajv-app/package.json
  • plugin/aop/test/aop.test.ts
  • plugin/controller/test/http/priority.test.ts
  • plugin/controller/test/http/request.test.ts
  • plugin/dal/test/fixtures/apps/dal-app/config/config.default.js
  • plugin/eventbus/test/eventbus.test.ts
  • standalone/standalone/test/fixtures/ajv-module-pass/package.json
Additional Context Used
Additional comments not posted (51)
standalone/standalone/test/fixtures/ajv-module/package.json (1)

1-6: The package.json for the test fixture simple is correctly structured and seems appropriate for its intended use in testing the AJV module integration.

plugin/ajv/test/fixtures/apps/ajv-app/config/module.json (1)

1-7: The module configuration for the AJV app test fixture appears correctly structured, with relative paths pointing to the necessary modules. Ensure these paths accurately reflect the project's directory structure.

core/ajv-decorator/index.ts (1)

1-3: The exports in index.ts are correctly set up, including those from @sinclair/typebox and local modules. Ensure the paths to local modules are accurate and that these modules exist as expected.

core/ajv-decorator/src/type/Ajv.ts (1)

1-5: The Ajv interface and the import of the Schema type from ajv/dist/2019 are correctly defined. Ensure the Schema type is compatible with the method signature and that the import path points to the intended AJV version.

plugin/ajv/tsconfig.json (1)

1-9: The TypeScript configuration for the AJV plugin appears correctly set up, extending the base configuration and specifying appropriate compiler options and exclusions. Ensure the baseUrl and the path to the base configuration are accurate.

plugin/ajv/tsconfig.pub.json (1)

1-10: The TypeScript configuration for publishing the AJV plugin appears correctly set up, extending the base configuration and specifying appropriate compiler options and exclusions. Ensure the baseUrl and the path to the base configuration are accurate, and the exclusion of the test directory is intentional for the publishing context.

plugin/ajv/test/fixtures/apps/ajv-app/config/config.default.js (1)

1-11: The default configuration for the AJV app test fixture appears correctly set up, with appropriate security settings. Ensure the ignoreJSON setting for CSRF aligns with the application's security requirements and best practices.

core/ajv-decorator/tsconfig.json (1)

1-12: The tsconfig.json configuration for the @eggjs/ajv-decorator package is correctly set up, extending the base configuration and specifying appropriate compiler options and exclusions.

plugin/ajv/test/fixtures/apps/ajv-app/config/plugin.js (1)

1-14: The plugin.js configuration correctly enables the necessary Egg.js plugins (tracer, tegg, teggConfig) following the framework's conventions.

plugin/ajv/typings/index.d.ts (1)

1-13: The TypeScript declarations in index.d.ts correctly extend the Egg.js Application interface with ajv functionality, following TypeScript best practices.

plugin/ajv/app.ts (1)

1-14: The AopAppHook class in app.ts correctly initializes the ajv instance on the Egg.js application, following the framework's conventions for application hooks.

plugin/config/test/DuplicateOptionalModule.test.ts (1)

5-5: Updating the describe block to reflect the new file path in DuplicateOptionalModule.test.ts improves test organization and clarity.

plugin/controller/test/lib/EggControllerLoader.test.ts (1)

7-7: Updating the describe block to reflect the new file path in EggControllerLoader.test.ts improves test organization and clarity.

plugin/tegg/test/NoModuleJson.test.ts (1)

5-5: Updating the describe block to reflect the new file path in NoModuleJson.test.ts improves test organization and clarity.

plugin/ajv/test/fixtures/apps/ajv-app/modules/demo/FooController.ts (1)

1-33: The FooController class demonstrates the intended use of AJV and TypeBox for request validation, aligning with the PR's objectives and showcasing best practices in using TypeScript and Egg.js decorators.

standalone/standalone/test/fixtures/ajv-module/foo.ts (3)

5-12: Consider adding additional validation rules or constraints to the RequestBodySchema to ensure robust data validation. For instance, adding minLength to the fullname field could prevent empty strings from being considered valid.


22-28: The main method currently uses a mock object for demonstration. Ensure that in the actual implementation, the body is correctly populated from a real request. This is crucial for the validation logic to be effectively tested and used.


24-24: Using {} as any for type casting can be unsafe. Consider initializing body with actual data from a request or using a safer type assertion method.

plugin/tegg/test/Subscription.test.ts (1)

6-6: The update of the test file path in the describe block is appropriate and reflects the new location within the project structure. This helps maintain clarity and organization in the test suite.

plugin/tegg/test/OptionalPluginModule.test.ts (1)

6-6: The update of the test file path in the describe block accurately reflects the new location within the project structure, ensuring better organization and clarity in the test suite.

plugin/tegg/test/close.test.ts (1)

5-5: The update of the test description to include a more specific path is a good practice, as it enhances the clarity and organization of the test suite.

plugin/ajv/test/ajv.test.ts (1)

5-5: The test suite for AJV integration is well-structured and follows best practices for testing. It's important to ensure comprehensive test coverage for various validation scenarios to fully leverage AJV's capabilities.

plugin/config/test/ReadModule.test.ts (1)

5-5: Updating the test file path in the describe block to reflect its new location is a good practice, enhancing the organization and clarity of the test suite.

plugin/tegg/test/SameProtoName.test.ts (1)

6-6: The update of the test file path in the describe block is appropriate and helps maintain clarity and organization within the test suite. It's crucial to ensure that tests cover scenarios involving same-named prototypes thoroughly.

standalone/standalone/test/fixtures/ajv-module-pass/foo.ts (2)

5-12: The schema definition using TypeBox is clear and concise. Consider adding more complex validation scenarios to fully test the capabilities of AJV and TypeBox.


22-32: The main method demonstrates a more realistic use case by initializing body with actual data. Ensure that in production, data is securely handled and validated against the schema to prevent injection attacks or data integrity issues.

Verification successful

The verification process has confirmed that the codebase uses this.ajv.validate for data validation, including in the specific instance mentioned in the review comment. This practice is crucial for ensuring data integrity and preventing injection attacks, aligning with the recommendation for secure data handling in production environments.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify secure handling of data in production
rg "this.ajv.validate(RequestBodySchema, body)" -C 5

Length of output: 54



Script:

#!/bin/bash
# Broaden the search to find any usage of data validation with AJV
rg "this.ajv.validate" -C 5

Length of output: 2676

plugin/controller/test/http/edgecase.test.ts (1)

5-5: The update to the test file path in the describe block is accurate and reflects the new location of the test file. This change helps in correctly identifying the test suite during test execution.

plugin/schedule/test/schedule.test.ts (1)

7-7: The update to the test file path in the describe block is accurate and reflects the new location of the test file. This change helps in correctly identifying the test suite during test execution.

plugin/tegg/test/OptionalModule.test.ts (1)

8-8: The update to the test file path in the describe block is accurate and reflects the new location of the test file. This change helps in correctly identifying the test suite during test execution.

plugin/controller/test/http/middleware.test.ts (1)

5-5: The update to the test file path in the describe block is accurate and reflects the new location of the test file. This change helps in correctly identifying the test suite during test execution.

plugin/controller/test/lib/ControllerMetaManager.test.ts (1)

5-5: The update to the test file path in the describe block is accurate and reflects the new location of the test file. This change helps in correctly identifying the test suite during test execution.

plugin/tegg/test/ModuleConfig.test.ts (1)

5-5: The update to the test file path in the describe block is accurate and reflects the new location of the test file. This change helps in correctly identifying the test suite during test execution.

plugin/dal/app.ts (1)

28-28: Removing await from deleteLifecycle calls can potentially improve the shutdown process by not waiting unnecessarily. However, ensure that these methods do not perform asynchronous operations that need to be awaited.

plugin/controller/test/http/module.test.ts (1)

5-5: The update to the test file path in the describe block is clear and aligns with the PR's objectives. This change helps maintain clarity and organization within the test suite.

plugin/tegg/test/AccessLevelCheck.test.ts (1)

6-6: The update to the test file path in the describe block is appropriate and reflects the broader reorganization within the project. This helps in maintaining clarity and organization within the test suite.

plugin/dal/package.json (1)

47-47: The update to the repository directory path in the package.json file is accurate and improves the discoverability of the source code within the repository.

standalone/standalone/package.json (1)

47-47: The addition of the @eggjs/tegg-ajv-plugin dependency is consistent with the PR's objectives and enhances the standalone module's capabilities with AJV-based validation.

plugin/aop/app.ts (1)

15-15: Specifying the parameter type as Application in the constructor enhances type safety and clarity, aligning with TypeScript best practices.

core/tegg/package.json (1)

38-38: The addition of the @eggjs/ajv-decorator dependency is a crucial part of integrating AJV and TypeBox into the Egg.js framework, enhancing the core tegg module's capabilities.

plugin/ajv/package.json (1)

1-70: The introduction of the @eggjs/tegg-ajv-plugin package configuration is well-structured and includes all necessary dependencies and metadata, aligning with the PR's objectives to enhance validation capabilities within the Egg.js framework.

plugin/ajv/lib/Ajv.ts (1)

1-69: The implementation of the Ajv class and the custom TEggAjvInvalidParamError error class is well-designed, enhancing the Egg.js framework's validation capabilities with AJV. The setup of the AJV instance with additional formats and keywords is thorough, demonstrating a good understanding of AJV's capabilities.

plugin/controller/test/http/params.test.ts (1)

5-5: The update of the test file path in the describe block is correct and reflects the new location of the test file accurately.

plugin/tegg/test/BackgroundTask.test.ts (1)

11-11: The update of the test file path in the describe block is correct and reflects the new location of the test file accurately.

plugin/controller/test/http/host.test.ts (1)

5-5: The update of the test file path in the describe block is correct and reflects the new location of the test file accurately.

plugin/controller/test/http/acl.test.ts (1)

5-5: The update of the test file path in the describe block is correct and reflects the new location of the test file accurately.

plugin/dal/test/dal.test.ts (1)

7-7: The update of the test file path in the describe block is correct and reflects the new location of the test file accurately.

plugin/controller/test/lib/HTTPMethodRegister.test.ts (1)

18-18: The update of the test file path in the describe block is correct and reflects the new location of the test file accurately.

plugin/tegg/test/EggCompatible.test.ts (1)

7-7: The update of the test file path in the describe block is correct and reflects the new location of the test file accurately.

plugin/orm/test/index.test.ts (1)

14-14: The update of the test file path in the describe block is correct and reflects the new location of the test file accurately.

standalone/standalone/src/Runner.ts (2)

106-109: The injection of the Ajv object into innerObjects is a crucial part of integrating AJV for validation. Ensure that the Ajv instance is correctly configured and that any necessary AJV plugins or custom settings are applied during instantiation.


261-264: The removal of await when calling deleteLifecycle in the destroy method is appropriate since these lifecycle utility functions do not return promises. This change should streamline the cleanup process without affecting functionality. However, ensure that all resources are correctly cleaned up and that there are no side effects from this change.

standalone/standalone/test/index.test.ts Outdated Show resolved Hide resolved
standalone/standalone/test/index.test.ts Outdated Show resolved Hide resolved
plugin/ajv/README.md Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 233c724 and f549dde.
Files selected for processing (2)
  • core/ajv-decorator/package.json (1 hunks)
  • plugin/ajv/package.json (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • core/ajv-decorator/package.json
  • plugin/ajv/package.json
Additional Context Used

plugin/ajv/README.md Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f549dde and 01ed5b1.
Files selected for processing (8)
  • core/ajv-decorator/index.ts (1 hunks)
  • core/ajv-decorator/src/enum/TransformEnum.ts (1 hunks)
  • core/ajv-decorator/test/Transform.test.ts (1 hunks)
  • plugin/ajv/package.json (1 hunks)
  • plugin/ajv/test/ajv.test.ts (1 hunks)
  • plugin/ajv/test/fixtures/apps/ajv-app/config/plugin.js (1 hunks)
  • plugin/ajv/test/fixtures/apps/ajv-app/modules/demo/FooController.ts (1 hunks)
  • plugin/ajv/typings/index.d.ts (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • core/ajv-decorator/index.ts
  • plugin/ajv/package.json
  • plugin/ajv/test/ajv.test.ts
  • plugin/ajv/test/fixtures/apps/ajv-app/modules/demo/FooController.ts
  • plugin/ajv/typings/index.d.ts
Additional Context Used
Additional comments not posted (3)
core/ajv-decorator/test/Transform.test.ts (1)

4-7: Consider adding more test cases to cover all values of the Transform enum. Testing only one value (trim) might not be sufficient to ensure the correctness of all enum values.

plugin/ajv/test/fixtures/apps/ajv-app/config/plugin.js (1)

1-19: The plugin configuration looks correct. Ensure that the integration with AJV and TypeBox is verified, as this file does not directly relate to those changes.

core/ajv-decorator/src/enum/TransformEnum.ts (1)

1-45: The TransformEnum is well-defined and covers a good range of string transformations. Consider adding unit tests for the toEnumCase transformation to ensure its behavior matches the documentation, especially since it involves unique case-insensitive enum values.

@fengmk2 fengmk2 marked this pull request as draft April 1, 2024 09:26
@fengmk2 fengmk2 marked this pull request as ready for review April 1, 2024 09:35
@fengmk2 fengmk2 requested a review from killagu April 1, 2024 09:35
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 01ed5b1 and 9ac1ec9.
Files selected for processing (6)
  • core/ajv-decorator/index.ts (1 hunks)
  • core/ajv-decorator/src/error/AjvInvalidParamError.ts (1 hunks)
  • plugin/ajv/README.md (1 hunks)
  • plugin/ajv/lib/Ajv.ts (1 hunks)
  • plugin/ajv/test/ajv.test.ts (1 hunks)
  • standalone/standalone/test/index.test.ts (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • core/ajv-decorator/index.ts
  • plugin/ajv/lib/Ajv.ts
  • plugin/ajv/test/ajv.test.ts
Additional Context Used
Additional comments not posted (2)
core/ajv-decorator/src/error/AjvInvalidParamError.ts (1)

1-21: The implementation of AjvInvalidParamError class follows best practices for extending native Error in TypeScript, properly initializing custom properties and setting the error name. Good job on ensuring that the error handling is robust and clear.

plugin/ajv/README.md (1)

1-128: The README for the @eggjs/tegg-ajv-plugin is well-written, providing clear installation, configuration, and usage instructions. It effectively demonstrates how to leverage AJV and TypeBox for request validation in Egg.js applications. Great job on addressing previous concerns and ensuring the documentation is clear and comprehensive.

standalone/standalone/test/index.test.ts Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9ac1ec9 and 52ff431.
Files selected for processing (6)
  • core/core-decorator/src/util/PrototypeUtil.ts (1 hunks)
  • plugin/ajv/lib/Ajv.ts (1 hunks)
  • plugin/ajv/typings/index.d.ts (1 hunks)
  • standalone/standalone/src/Runner.ts (1 hunks)
  • standalone/standalone/test/fixtures/ajv-module-pass/foo.ts (1 hunks)
  • standalone/standalone/test/fixtures/ajv-module/foo.ts (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • plugin/ajv/lib/Ajv.ts
  • plugin/ajv/typings/index.d.ts
  • standalone/standalone/src/Runner.ts
  • standalone/standalone/test/fixtures/ajv-module-pass/foo.ts
  • standalone/standalone/test/fixtures/ajv-module/foo.ts
Additional Context Used
Additional comments not posted (1)
core/core-decorator/src/util/PrototypeUtil.ts (1)

124-129: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [134-146]

The removal of the return type declaration from getMultiInstanceProperty might reduce clarity for developers on what the method returns. While TypeScript's type inference might still provide this information, explicitly documenting complex return types can enhance code readability and maintainability. Consider adding a detailed comment explaining the return type if not adding it back directly.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 52ff431 and a116170.
Files selected for processing (4)
  • plugin/ajv/README.md (1 hunks)
  • plugin/dal/README.md (19 hunks)
  • standalone/standalone/package.json (1 hunks)
  • standalone/standalone/test/index.test.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • standalone/standalone/package.json
Additional comments not posted (12)
plugin/ajv/README.md (5)

1-1: The title of the README correctly identifies the plugin as @eggjs/tegg-ajv-plugin. However, the static analysis tool flagged a possible spelling mistake, which seems to be a false positive in this context.


3-3: The introduction references egg-typebox-validate as a best practice, which is relevant and provides context for the integration of ajv and typebox. This is a good approach for explaining the motivation behind the plugin.


36-39: The configuration snippet for enabling the @eggjs/tegg-ajv-plugin is clear and concise. However, it's important to ensure that the plugin name teggDal accurately reflects its purpose, especially since it seems to be related to data access layer (DAL) functionalities. If this is a typo or misconfiguration, it should be corrected to match the AJV plugin's context.


64-89: The example provided for defining a validation schema using typebox is clear and demonstrates how to use the plugin effectively. This is a good practice for illustrating the usage of the plugin in a practical scenario.


101-143: The section detailing how to use the validation schema in a controller is comprehensive and informative. It demonstrates dependency injection, schema validation, and error handling with AjvInvalidParamError. This example is valuable for users looking to implement validation in their applications.

standalone/standalone/test/index.test.ts (2)

5-5: The change from ModuleConfigs to ModuleConfig is noted. Ensure that this change aligns with the intended usage within the framework and does not introduce any breaking changes or inconsistencies.


253-289: The addition of tests for AJV validation, including scenarios where validation fails and passes, is a significant improvement. These tests ensure that the AJV integration works as expected and can handle both success and error cases effectively. It's good practice to cover a broad range of validation cases, and these tests seem to do so.

plugin/dal/README.md (5)

8-8: The installation instructions are clear and provide the necessary steps to install the @eggjs/tegg-dal-plugin along with its dependencies. This is helpful for users looking to integrate the plugin into their projects.


65-65: The section on configuring the module.yml for MySQL data sources is informative and provides a clear example of how to set up a data source. This is crucial for users to understand how to configure their modules to use the DAL plugin effectively.


78-84: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [81-117]

The explanation and example of defining a table structure using TableModel are comprehensive. It covers table configuration, columns, and indexing, which are essential aspects of using the DAL plugin for database interactions.


572-578: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [558-607]

The section on custom SQL definitions and how to define and use them in extensions and DAOs is particularly useful. It demonstrates the flexibility of the DAL plugin in allowing custom SQL queries, which can be essential for complex database operations.


618-618: The explanation of DataSource usage within DAOs is clear and highlights the plugin's capability to deserialize MySQL data into classes. This feature is a significant advantage for developers working with TypeScript and object-oriented patterns.

Copy link
Contributor

@killagu killagu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a116170 and 4afdd06.
Files selected for processing (1)
  • core/ajv-decorator/package.json (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • core/ajv-decorator/package.json

Copy link

codecov bot commented Apr 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.57%. Comparing base (a411f04) to head (3698ac7).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #201      +/-   ##
==========================================
- Coverage   92.42%   91.57%   -0.85%     
==========================================
  Files         277      282       +5     
  Lines        6589     6555      -34     
  Branches      991      944      -47     
==========================================
- Hits         6090     6003      -87     
- Misses        499      552      +53     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@killagu killagu merged commit 9fd585d into master Apr 2, 2024
12 of 13 checks passed
@killagu killagu deleted the teggAjv branch April 2, 2024 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

基于 typebox 提供请求入参 Validator 让参数校验无比简单
2 participants